import java.util.Stack;

public class demo1 {
    public static void main(String[] args) {

    }

    public boolean validateStackSequeces(int[] pushed,int[] popped){
        Stack<Integer> stack=new Stack<>();
        int i=0;
       for (int temp:pushed){
           stack.push(temp);
           while (!stack.isEmpty()&&stack.peek()==popped[i]){
               stack.pop();
               i++;
           }

        }
       return i== pushed.length;
    }
}
